package com.lnking.lnkingplace.service.impl;


import com.lnking.lnkingplace.mapper.FourEnterpriseMapper;
import com.lnking.lnkingplace.model.dto.cultureEnterprise.CultureEnterpriseImport;
import com.lnking.lnkingplace.model.dto.fourEnterprise.FourEnterpriseImport;
import com.lnking.lnkingplace.model.entity.CultureEnterprise;
import com.lnking.lnkingplace.model.entity.FourEnterprise;
import com.lnking.lnkingplace.model.request.fourEnterprise.FourAddRequest;
import com.lnking.lnkingplace.model.request.fourEnterprise.FourUpdateRequest;
import com.lnking.lnkingplace.service.IFourEnterpriseService;
import com.lnking.starter.export.utils.ImportOption;
import com.lnking.starter.export.utils.ImportUtils;
import com.lnking.starter.mybatis.service.impl.CustomServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 四上企业表 服务实现类
 * </p>
 *
 * @author zhangqt
 * @since 2022-10-05
 */
@Service
public class FourEnterpriseServiceImpl extends CustomServiceImpl<FourEnterpriseMapper, FourEnterprise> implements IFourEnterpriseService {

    @Override
    public void add(FourAddRequest params) {
        FourEnterprise info = new FourEnterprise();
        BeanUtils.copyProperties(params,info);
        info.setCreateTime(LocalDateTime.now());
        this.baseMapper.insert(info);
    }

    @Override
    public void update(FourUpdateRequest params) {
        FourEnterprise info = new FourEnterprise();
        BeanUtils.copyProperties(params,info);
        info.setCreateTime(LocalDateTime.now());
        this.baseMapper.updateById(info);
    }

    @Override
    public void importExcel(MultipartFile file) throws Exception {
        ImportOption option = new ImportOption.Builder().build();
        List<FourEnterpriseImport> result =  ImportUtils.importExcel(file, FourEnterpriseImport.class,option);
        for (FourEnterpriseImport fourEnterpriseImport : result) {
            if(StringUtils.isNotBlank(fourEnterpriseImport.getEnterpriseName())){
                FourEnterprise info = new FourEnterprise();
                BeanUtils.copyProperties(fourEnterpriseImport,info);
                info.setCreateTime(LocalDateTime.now());
                if(StringUtils.isNotBlank(fourEnterpriseImport.getYear())){
                    info.setYear(Integer.valueOf(fourEnterpriseImport.getYear()));
                }
                if(StringUtils.isNotBlank(fourEnterpriseImport.getRevenue())){
                    info.setRevenue(Float.valueOf(fourEnterpriseImport.getRevenue()));
                }
                if(StringUtils.isNotBlank(fourEnterpriseImport.getWagesMonth())){
                    info.setWagesMonth(Float.valueOf(fourEnterpriseImport.getWagesMonth()));
                }
                this.baseMapper.insert(info);
            }

        }
    }
}
